package com.ruoyi.finance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.finance.mapper.InvoiceTypesMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.InvoiceTypes;
import com.ruoyi.finance.service.IInvoiceTypesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发票种类Controller
 *
 * @author ruoyi
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/system/types")
public class InvoiceTypesController extends BaseController
{
    @Autowired
    private IInvoiceTypesService invoiceTypesService;

    @Autowired
    private InvoiceTypesMapper invoiceTypesMapper;

    /**
     * 查询发票种类列表
     */
    @PreAuthorize("@ss.hasPermi('system:types:list')")
    @GetMapping("/list")
    public TableDataInfo list(InvoiceTypes invoiceTypes)
    {
        startPage();
        List<InvoiceTypes> list = invoiceTypesService.selectInvoiceTypesList(invoiceTypes);
        return getDataTable(list);
    }

    @GetMapping("/tolist")
    public AjaxResult tolist()
    {

        List<InvoiceTypes> invoiceTypes = invoiceTypesMapper.selselist();
        return AjaxResult.success(invoiceTypes);
    }

    /**
     * 导出发票种类列表
     */
    @PreAuthorize("@ss.hasPermi('system:types:export')")
    @Log(title = "发票种类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InvoiceTypes invoiceTypes)
    {
        List<InvoiceTypes> list = invoiceTypesService.selectInvoiceTypesList(invoiceTypes);
        ExcelUtil<InvoiceTypes> util = new ExcelUtil<InvoiceTypes>(InvoiceTypes.class);
        util.exportExcel(response, list, "发票种类数据");
    }

    /**
     * 获取发票种类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:types:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(invoiceTypesService.selectInvoiceTypesById(id));
    }

    /**
     * 新增发票种类
     */
    @PreAuthorize("@ss.hasPermi('system:types:add')")
    @Log(title = "发票种类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InvoiceTypes invoiceTypes)
    {
        return toAjax(invoiceTypesService.insertInvoiceTypes(invoiceTypes));
    }

    /**
     * 修改发票种类
     */
    @PreAuthorize("@ss.hasPermi('system:types:edit')")
    @Log(title = "发票种类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InvoiceTypes invoiceTypes)
    {
        return toAjax(invoiceTypesService.updateInvoiceTypes(invoiceTypes));
    }

    /**
     * 删除发票种类
     */
    @PreAuthorize("@ss.hasPermi('system:types:remove')")
    @Log(title = "发票种类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(invoiceTypesService.deleteInvoiceTypesByIds(ids));
    }
}
